<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!-- START DEFAULT DATATABLE -->
<link rel="stylesheet" type="text/css" id="theme" href="/statics/css/theme-default.css"/>
<div class="panel panel-default">
    <div class="panel-heading row">
            <h3 class="panel-title">问题表单</h3>
            <ul class="panel-controls pull-right">
                <li><a href="/admin/suggest/edit.jspa?page=${param.page}"><i class="fa fa-plus"></i></a></li>
                <li>
                    <a href="/admin/suggest/suggestModel.jspa?page=${param.parentPage}">
                        <i class="fa fa-arrow-left"></i>
                    </a>
                </li>
            </ul>
    </div>
    <div class="panel-body">
        <table class="table">
            <thead>
            <tr>
                <th>表单Id</th>
                <th>表单名称</th>
                <th>创建时间</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody id = "t1">
            <c:if test="${menus.size()>0}">
            <c:forEach items="${menus}" var="root">
                <tr class="item-comment comment-quote info" id="${root.menuId}">
                    <td>${root.itemType}</td>
                    <td><img src="/upload/${root.imageFile}" height="30px"></td>
                    <td>${root.itemName}</td>
                    <td>${root.itemUnit}</td>
                    <td>${root.itemDescription}</td>
                    <td>${root.itemPrice}</td>
                    <td><input value="${root.storeNum}" size="10px" style="text-align:center"/><input type="button" id="${root.menuId}" value="更改" onclick="updateStores(this)"/></td>
                    <script type="text/javascript">
                        function updateStores(sto){
                            var nm = $(sto).prev().prop("value");
                            var md = $(sto).prop("id");
                            if($(sto).prev().prop("value")>0){
                                $.ajax({
                                    type:"post",
                                    url:"${pageContext.request.contextPath}/admin/storeUpdate.jspa",
                                    data:{menuId:md,nums:nm},
                                    success:function(){
                                        layer.open({content:"修改成功",time:3});
                                    }
                                });
                            }else{
                                layer.open({content:"库存数量不规范",time:1});
                            }
                        }
                    </script>
                        <%--上下架的图标--%>
                    <td>
                        <label class="switch">
                            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input  id = "${root.menuId}" type="checkbox" ${root.isUping=="1"?"checked":"" } value="0" onclick="ups(this)"/>
                            <span></span>
                        </label>
                    </td>
                    <td>
                        <button class="btn btn-info btn-rounded btn-sm" title="修改菜品" onclick="goEdit(this)"><span
                                class="fa fa-pencil"></span></button>&nbsp;&nbsp;&nbsp;&nbsp;
                            <%--<button class="btn btn-success btn-rounded btnsm" title="上架" onclick="goUping(this)"><span--%>
                            <%--class="fa fa-mail-forward"></span></button>--%>
                        <button class="btn btn-danger btn-rounded btn-sm" title="删除菜品" id="${root.menuId}" onClick="goCancel2(this)"><span
                                class="fa fa-times"></span></button>
                    </td>
                </tr>
            </c:forEach>
            </tbody>
        </table>
        <div class="panel-footer">
            <ul class="pagination pagination-sm pull-right">
                <c:if test="${curs}<=1">
                    <li><a href="#">&laquo;</a></li>
                </c:if>
                <c:if test="${curs>1}">
                    <li><a href="/admin/queryMenus2.jspa?itemName=${itemName}&itemType=${itemType}&curpage=${curs-1}">&laquo;</a></li>
                </c:if>
                <c:forEach begin="1" end="${pa}" step="1" var="i">
                    <c:if test="${curs==i}">
                        <li class="active"><a href="/admin/queryMenus2.jspa?itemName=${itemName}&itemType=${itemType}&curpage=${i}">${i}</a></li>
                    </c:if>
                    <c:if test="${curs!=i}">
                        <li><a href="/admin/queryMenus2.jspa?itemName=${itemName}&itemType=${itemType}&curpage=${i}">${i}</a></li>
                    </c:if>
                </c:forEach>
                <c:if test="${curs>=pa}">
                    <li class="disabled"><a href="#">&raquo;</a></li>
                </c:if>
                <c:if test="${curs<pa}">
                    <li><a href="/admin/queryMenus2.jspa?itemName=${itemName}&itemType=${itemType}&curpage=${curs+1}">&raquo;</a></li>
                </c:if>
            </ul>
        </div>
        </c:if>
    </div>
</div>

<script>
    function fun(){
        window.location.href="/admin/queryMenuOrders.jspa?itemName="+$("#input1").val()+"&itemType="+$("#input2").val();
    }
    //
    function goCancel2(ths){
        window.location.href="/admin/deleteMenu.jspa?menuId="+$(ths).prop("id");
    }
    function goCancel(ths){
        window.location.href="/admin//isUpDown.jspa?menuId="+$("#t1>tr:eq(0)").prop("id");
    }
    function goUping(ths){
        window.location.href="/admin/isUpDown2.jspa?menuId="+$("#t1>tr:eq(0)").prop("id");
    }
    function goEdit(ths){
        var ids = $(ths).parent().parent().prop("id");
        var names = $("#input1").val();
        var types = $("#sele1").val();
        var curs = $("#hid1").val();
        window.location.href="/admin/updateMenus.jspa?menuId="+ids+"&itemName="+names+"&itemType="+types+"&curpage="+curs;
    }
    function ups(tt){
        if($(tt).prop("checked")==true){
            $.ajax({
                type:"post",
                url:"${pageContext.request.contextPath}/admin/isUpDown2.jspa",
                data:"menuId="+$(tt).prop("id"),
                success:function(){
                }
            });
        }else{
            $.ajax({
                type:"post",
                url:"${pageContext.request.contextPath}/admin/isUpDown.jspa",
                data:"menuId="+$(tt).prop("id"),
                success:function(){
                }
            });
        }
    }
    $(function(){
        $("#bus").click(function(){
            window.location.href="/admin/menu/addMenu.jspa";
        });
    })
</script>